# -*- coding:utf-8 -*-
# CREATED BY: jiangbohuai
# CREATED ON: 2021/4/30 5:22 PM
# LAST MODIFIED ON:
# AIM:
from typing import List
import numpy as np


def feature_scaling_single(a_feature: np.ndarray, to_range: List[float]):
    assert len(to_range) >= 2
    a, b = sorted(to_range[0:2])
    min_v = np.min(a_feature)
    max_v = np.max(a_feature)
    return a + (a_feature - min_v) * (b - a) / (max_v - min_v)

def feature_scaling1D(features: np.ndarray, to_range: List[float]):
    m, n = np.shape(features)
    for i in range(m):
        features[:,i] = feature_scaling_single(features[:,i], to_range)
    return features